package com.atguigu.exam;

import java.io.*;

/**
 * 4.使用缓冲流实现a.jpg文件复制为b.jpg文件的操作4.使用缓冲流实现a.jpg文件复制为b.jpg文件的操作
 * @author xbd
 * @create 2021-05-30 14:43
 */
public class CopyImageTest {
    public static void main(String[] args) {

        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            bis = new BufferedInputStream(new FileInputStream(new File("a.jpg")));
            bos = new BufferedOutputStream(new FileOutputStream(new File("b.jpg")));

            byte[] buffer = new byte[1024];
            int len;
            while((len = bis.read(buffer)) != -1){
                bos.write(buffer,0,len);
            }
            System.out.println("使用缓冲流实现a.jpg文件复制为b.jpg文件的操作--->成功");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(bos != null){
                try {
                    bos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(bis != null){
                try {
                    bis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
